export const friendlyTimeAgo = (timestamp: number | Date) => {
    const now = new Date();
    const then = new Date(timestamp);

    const secondsDiff = Math.floor((now.getTime() - then.getTime()) / 1000);
    const minutesDiff = Math.floor(secondsDiff / 60);
    const hoursDiff = Math.floor(minutesDiff / 60);
    const daysDiff = Math.floor(hoursDiff / 24);

    let friendlyTime;

    if (secondsDiff < 60) {
        friendlyTime = '刚刚';
    } else if (minutesDiff >= 1 && minutesDiff <= 44) {
        friendlyTime = `${minutesDiff}分钟前`;
    } else if (hoursDiff >= 1 && hoursDiff <= 23) {
        friendlyTime = `${hoursDiff}小时前`;
    } else if (daysDiff >= 1 && daysDiff <= 30) {
        friendlyTime = `${daysDiff}天前`;
    } else {
        // 若超过30天，使用默认日期格式
        friendlyTime = then.toLocaleDateString('default', {
            year: 'numeric',
            month: 'short',
            day: 'numeric',
            hour: 'numeric',
            minute: 'numeric',
        });
    }

    return friendlyTime;

}